﻿<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:Drawing="clr-namespace:GraphLight.Drawing" xmlns:Controls="clr-namespace:GraphLight.Controls">

    <ControlTemplate x:Key="nodeTemplate" TargetType="Drawing:Node">
        <Grid x:Name="LayoutRoot">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="SelectedStates">
                    <VisualState x:Name="SelectionOn" />
                    <VisualState x:Name="SelectionOff" />
                </VisualStateGroup>
                <VisualStateGroup x:Name="HighlightedStates">
                    <VisualState x:Name="HighlightOn">
                        <Storyboard>
                            <ColorAnimation To="Red" Duration="00:00:00" Storyboard.TargetName="path"
                                    Storyboard.TargetProperty="(Stroke).(SolidColorBrush.Color)" />
                            <DoubleAnimation Storyboard.TargetName="path" Duration="00:00:00"
                                    Storyboard.TargetProperty="StrokeThickness" To="3" />
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="HighlightOff">
                        <Storyboard BeginTime="00:00:00.3">
                            <ColorAnimation To="Black" Duration="00:00:00" Storyboard.TargetName="path"
                                    Storyboard.TargetProperty="(Stroke).(SolidColorBrush.Color)" />
                            <DoubleAnimation Storyboard.TargetName="path" Duration="00:00:00"
                                    Storyboard.TargetProperty="StrokeThickness" To="1" />
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <i:Interaction.Behaviors>
                <ei:DataStateBehavior Value="True" TrueState="SelectionOn" FalseState="SelectionOff"
                        Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                <ei:DataStateBehavior Value="True" TrueState="HighlightOn" FalseState="HighlightOff"
                        Binding="{Binding Path=IsHighlighted, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
            </i:Interaction.Behaviors>
            <Path x:Name="path" Stroke="Black" Fill="LightBlue" Stretch="Fill" Data="{Binding ShapeData}" />
            <ContentPresenter x:Name="content" Content="{TemplateBinding Content}"
                    ContentTemplate="{TemplateBinding ContentTemplate}" Margin="10" />
        </Grid>
    </ControlTemplate>

    <Style TargetType="Drawing:Node">
        <Setter Property="Canvas.Left" Value="{Binding Data.Left}" />
        <Setter Property="Canvas.Top" Value="{Binding Data.Top}" />
        <Setter Property="Canvas.ZIndex" Value="{Binding Data.ZIndex}" />
        <!--Setter Property="Controls:DragDropManager.AllowDrag" Value="True" /-->
        <Setter Property="Controls:DragDropManager.AllowDrag" Value="{Binding Data.IsSelected}" />
        <Setter Property="IsSelected" Value="{Binding Data.IsSelected}" />
        <Setter Property="IsHighlighted" Value="{Binding Data.IsHighlighted}" />
        <Setter Property="Template" Value="{StaticResource nodeTemplate}" />
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock Text="{Binding Data.Label}" VerticalAlignment="Center"
                            HorizontalAlignment="Center" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>